//
//  LDCEditMarkViewController.m
//  LaiKeDaoClient
//
//  Created by lidechen on 15/10/22.
//  Copyright © 2015年 LKD. All rights reserved.
//

#import "LDCEditMarkViewController.h"

@implementation LDCEditMarkViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNaviLeftButton:@""];
    [self setNaviTitle:@"添加患者"];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self buildViews];
}

-(void)buildViews{
    NSArray *ar = @[@"头疼",@"输卵管阻塞",@"恶心",@"四肢无力",@"腰膝酸软",@"便秘",@"水肿",@"失眠",@"脱发",@"肚子疼",@"头晕"];
    [self tagView:ar];
    
}

- (void)tagView:(NSArray *)textArray{
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectZero];
    bgView.backgroundColor = [UIColor clearColor];
    
    CGFloat total_x = 14.0f, total_y = 6.0f, labelH = 28.0f;
    NSInteger line = 1;
    for (int i=0; i<textArray.count; ++i) {
        NSString *msgString = textArray[i];
        
        CGFloat padding_x = 14.0f, padding_y = 15.0f;
        
        // iOS7depre
        CGSize size = [msgString sizeWithFont:[UIFont systemFontOfSize:12.0f]
                            constrainedToSize:CGSizeMake(250.0f, 22.0f) lineBreakMode:NSLineBreakByWordWrapping];
        size.width += 10;
        CGFloat next_x = total_x + (size.width+padding_x);
        
        if (next_x > SCREEN_WIDTH) {// 另起一行
            line += 1;
            if (line > 3) {
                break;
            }
            
            total_y = total_y + (labelH+padding_y);
            total_x = 14.0f;
        }
        else{
            //total_x = total_x + (size.width+padding_x);
        }
        
        
        UIButton *textButton = [[UIButton alloc] initWithFrame:CGRectMake(total_x, total_y, size.width, labelH)];
        textButton.tag = i;// tag作为热词数组索引
        [textButton addTarget:self action:@selector(textButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [textButton setTitle:msgString forState:UIControlStateNormal];
        textButton.titleLabel.font = [UIFont systemFontOfSize:12.0f];
        [textButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        textButton.backgroundColor = [UIColor whiteColor];
        textButton.titleEdgeInsets = UIEdgeInsetsMake(1.0, 0.0, 0.0, 0.0);
        [bgView addSubview:textButton];
        textButton.layer.borderColor = [UIColor colorWithHexString:@"0xF2F2F2"].CGColor;
        textButton.layer.borderWidth = 1;
        
        total_x = total_x + (size.width+padding_x);//累加
    }
    
    bgView.frame = CGRectMake(0, 32, SCREEN_WIDTH, total_y+labelH);//
    [self.view addSubview:bgView];
}

- (void)textButtonAction:(UIButton *)btn
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
